
/**
 * Overlays c1 over c2 whereever c1 has an intensity > threshold
 */
vec4 overlay(vec4 c1, vec4 c2, float threshold){
	float intensity = max(c1.r, max(c1.g, c1.b));
	vec4 result = c2;
	if(intensity >= threshold){
		result = c1;
	}
	return result;
}

vec4 blend(vec4 c1, vec4 c2, float w){
	return mix(c1, c2, w);
}

/**
 * Calculates a bumpmap with given offset at given coordinates for the
 * provided sample field, then applies the bumpmap to the background pixel.
 */
vec4 bumpmap(vec4 backgroundColor, sampler2D tex_to_bumpmap, vec2 coord, vec2 vpdims, vec2 offset){
	return backgroundColor * (edge(tex_to_bumpmap, coord, vpdims, offset) + vec4(1.0));
}


